#pragma once 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;

#include "logcplus_util.h"
#include "logcplus_string.hpp"

#include "logcplus_common.h"
#include "logcplus_properties.h"
#include "logcplus_layout.h"

#include "logcplus_fileutil.h"

namespace logcplus
{
    class logcplus_base_writer
    {
    public:
        logcplus_base_writer(logcplus_type_t logcplus_logtype);
        virtual ~logcplus_base_writer(){};
    public:
        bool IsEnabledFor(int level);

        inline void SetLogName(const string& sLogName)           ;
        inline void SetLogLevel(logcplus_level_t nLogLevel)      ;
        inline void SetTagName(const string& sTagName)           ;
        inline void SetMainDir(const string& mainDir)            ;
        inline void SetLayout(const string& sLayout)             ;
        inline void SetBufferLevel(uint16_t nBufferLevel)        ;
        inline void SetBufferSize(uint32_t  nBufferSize )        ;
        inline void SetMaxBackups(uint32_t  nMaxBackups )        ;
        inline void SetMaxFileSize(uint32_t nMaxFileSize)        ;
        inline void SetExpireDays(uint16_t  nExpireDays )        ;
        inline void SetRunDate(uint32_t nRunDate)                ;
        inline void SetLogType( logcplus_type_t nLogType)        ;
        inline void SetReserved(const string& Reserved)          ;
        
        inline string   GetLogName()         ;
        inline uint16_t GetLogLevel()        ;
        inline string   GetTagName()         ;
        inline string   GetMainDir()         ;
        inline string   GetLogFileDir()      ;
        inline string   GetLogFilePath()     ;
        inline CFile&   GetLogHandle()       ;
        inline uint16_t GetLogType()         ;
        inline uint64_t GetLogNbr()          ;
        inline uint32_t GetMaxFileSize()     ;
        inline uint32_t GetMaxBackups()      ;
        inline uint16_t GetBufferLevel()     ;

        int  SetAttrs(const string& logger_name,logcplus_properties& attrs,const string& suffix= string());
        int  SetParams(const logcplus_params& params,const string& suffix);    

        //! virtual function interface 
        virtual int  LogInit() = 0;
        virtual int  LogInit(const string& sLogName, int nLogLevel,const string& sLogNode = string()) = 0;
        virtual int  LogBegin(uint64_t logMsgId = 0) = 0;
        virtual void LogWrite(const char* File, const char* Function, int Line,  int Level, const char* LogMsg) = 0;
        virtual void LogWrite(const char* sLogText,int nFlag=0) = 0;
        virtual void LogCommit() = 0;
        virtual int  LogUInit() = 0;
        
        virtual void Trace(  const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;
        virtual void Debug(  const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;
        virtual void Info(   const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;
        virtual void Warn(   const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;
        virtual void Error(  const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;
        virtual void Fatal(  const char* File, const char* Function, int Line,  const char* Fmt, ...) = 0;    

        virtual void LogHex( const char* File, const char* Function, int Line,  int Level, const void* data, size_t dataSize) = 0;
        virtual void Logger( const char* File, const char* Function, int Line,  int Level, const char* Fmt, ...) = 0 ;
        virtual void WLog(   const char* File, const char* Function, int Line,  int Level, const char* sLogText) = 0 ;

    protected:
        logcplus_level_t  m_logLevel;
        logcplus_type_t  m_logType;
        bool m_status;
        CFile m_handle;
        std::string m_tagname;
        std::string m_logname;
        std::string m_layout;
        std::string m_mainDir;
        std::string m_fullDir;
        std::string m_logFile;
        std::string m_fileName;
        uint16_t m_bufferLevel;
        uint32_t m_bufferSize;
        uint32_t m_maxBackups;
        uint32_t m_maxFileSize;
        uint16_t m_expireDays;
        uint32_t m_rundate;        
        uint64_t m_logMsgId;     
        std::string m_reserved;
    };
    
    inline void logcplus_base_writer::SetLogName(const string& sLogName)     { m_logname     = sLogName;     };
    inline void logcplus_base_writer::SetLogLevel(logcplus_level_t nLogLevel){ m_logLevel    = nLogLevel;    };
    inline void logcplus_base_writer::SetTagName(const string& sTagName)     { m_tagname     = sTagName;     };
    inline void logcplus_base_writer::SetMainDir(const string& mainDir)      { m_mainDir     = mainDir;      };
    inline void logcplus_base_writer::SetLayout(const string& sLayout)       { m_layout      = sLayout;      };
    inline void logcplus_base_writer::SetBufferLevel(uint16_t nBufferLevel)  { m_bufferLevel = nBufferLevel; };
    inline void logcplus_base_writer::SetBufferSize(uint32_t  nBufferSize )  { m_bufferSize  = nBufferSize;  };
    inline void logcplus_base_writer::SetMaxBackups(uint32_t  nMaxBackups )  { m_maxBackups  = nMaxBackups;  };
    inline void logcplus_base_writer::SetMaxFileSize(uint32_t nMaxFileSize)  { m_maxFileSize = nMaxFileSize; };
    inline void logcplus_base_writer::SetExpireDays(uint16_t  nExpireDays )  { m_expireDays  = nExpireDays;  };
    inline void logcplus_base_writer::SetRunDate(uint32_t nRunDate)          { m_rundate     = nRunDate;     };
    inline void logcplus_base_writer::SetLogType( logcplus_type_t nLogType)  { m_logType     = nLogType;     };
    inline void logcplus_base_writer::SetReserved(const string& sReserved)   { m_reserved    = sReserved;    };
    
    inline string   logcplus_base_writer::GetMainDir()         { return m_mainDir;    };
    inline string   logcplus_base_writer::GetLogFileDir()      { return m_fullDir;    };
    inline string   logcplus_base_writer::GetLogFilePath()     { return m_logFile;    };
    inline CFile&   logcplus_base_writer::GetLogHandle()       { return m_handle;     };
    inline uint16_t logcplus_base_writer::GetLogType()         { return m_logType;    };
    inline uint64_t logcplus_base_writer::GetLogNbr()          { return m_logMsgId;   };
    inline uint32_t logcplus_base_writer::GetMaxFileSize()     { return m_maxFileSize;};
    inline uint32_t logcplus_base_writer::GetMaxBackups()      { return m_maxBackups; };
    inline uint16_t logcplus_base_writer::GetBufferLevel()     { return m_bufferLevel;};    
    inline string   logcplus_base_writer::GetLogName()         { return m_logname;   };
    inline string   logcplus_base_writer::GetTagName()         { return m_tagname;   };
    inline uint16_t logcplus_base_writer::GetLogLevel()        { return m_logLevel;   };

}; 
